<?php
/**
 * User: hufeng
 * Date: 2017/12/1
 * Desc: 异步任务
 */
date_default_timezone_set('PRC');
$serv = new swoole_server("127.0.0.1", 8077);

//设置异步任务的工作进程数量
$serv->set(array(
    'task_worker_num' => 2,
    'daemonize' => true //是否作为守护进程
));

define('BASEDIR',__DIR__);
require 'App/Common/Conf/const.php';
require 'vendor/autoload.php';
require 'SasPHP/SasTask.php';

$serv->on('start', function($serv) {
    cli_set_process_title("sd_task");
});
//投递异步任务
$serv->on('receive', function($serv, $fd, $from_id, $data) {
    $task_id = $serv->task($data);
});
//处理异步任务
$serv->on('task', function ($serv, $task_id, $from_id, $data) {
    $_POST['task'] = $data;
    SasPHP\SasTask::start();
    $serv->finish("OK");
});
//处理异步任务的结果
$serv->on('finish', function ($serv, $task_id, $data) {
});
$serv->start();